package com.sy.core.util;

import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.*;

/**
 * 配置文件读取类
 *
 * @Description:
 * @Title: PropertiesUtils.java
 * @Package com.jobo.core.utils
 * @author Chong.caixin
 * @date 2018年3月20日
 * @version V1.0
 */
public class PropertiesUtils {

    /**
     * url:配置文件路径
     *
     * @Description:
     * @Title: getProperties
     * @Package com.jobo.core.utils
     * @author Chong.caixin
     * @date 2018年3月20日
     * @version V1.0
     */
    public static Properties getProperties(String url) {
        Properties props = new Properties();

        try {
            props = PropertiesLoaderUtils.loadAllProperties(url);
            return props;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List<Object> getPropertiesMap(String url) {
        Properties props = new Properties();
        ArrayList<Object> map = new ArrayList<>();
        try {
            props = PropertiesLoaderUtils.loadAllProperties(url);
            Set<Map.Entry<Object, Object>> set = props.entrySet();
            for (Object o : set) {
                Map.Entry entry = (Map.Entry) o;
                map.add(entry.getValue());
            }
            return map;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
